package com.zzb.codegenerator;

import com.zzb.codegenerator.bean.ProjectMeta;
import com.zzb.codegenerator.config.GeneratorConfig;
import com.zzb.codegenerator.config.GeneratorConfigPropertiesFactory;
import com.zzb.codegenerator.generator.FreeMarkerGenerator;
import com.zzb.codegenerator.generator.IGenerator;
import com.zzb.codegenerator.generator.table.TableMetaFactoryBean;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 主程序
 */
public class Main {
    public static void main(String[] args) {
        try {
            //生成配置类
            GeneratorConfig config = new GeneratorConfigPropertiesFactory().build();
            //获取tableMeta列表
            List<ProjectMeta> projectMetaList = TableMetaFactoryBean.createProjectMetaList(config);
            //执行生成方法
            IGenerator iGenerator = null;
            if("freemarker".equals(config.getTemplateType()) || StringUtils.isBlank(config.getTemplateType())){
                iGenerator = new FreeMarkerGenerator();
            }
            if(iGenerator == null){
                throw new Exception("请选择模板类型，现在支持freemarker");
            }
            iGenerator.generator(config,projectMetaList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
